package classes;

import java.util.ArrayList;

public class UserHandler {
	private static UserHandler instance = null;
	private ArrayList<User> _listeUser;
	private User userLogged = null;
	private ArrayList<Event> _listeEvent;
	
	protected UserHandler(){
		_listeUser = new ArrayList<User>();
		_listeUser.add(new User("user", "password", "M", "asd@asd.com", "User", "name"));
		_listeUser.add(new User("admin", "admin", "M", "asd@asd.com", "Admin", "Admin"));
		_listeUser.add(new User("z", "z", "M", "z@z.z", "Zed", "zed"));
		_listeUser.add(new User("a", "z", "M", "z@z.z", "z", "a"));
		_listeUser.add(new User("user", "password", "M", "asd@asd.com", "User", "name"));
		_listeUser.add(new User("admin", "admin", "M", "asd@asd.com", "Admin", "Admin"));
		_listeUser.add(new User("z", "z", "M", "z@z.z", "Zed", "zed"));
		_listeUser.add(new User("a", "z", "M", "z@z.z", "z", "a"));
		_listeUser.add(new User("user", "password", "M", "asd@asd.com", "User", "name"));
		_listeUser.add(new User("admin", "admin", "M", "asd@asd.com", "Admin", "Admin"));
		_listeUser.add(new User("z", "z", "M", "z@z.z", "Zed", "zed"));
		_listeUser.add(new User("a", "z", "M", "z@z.z", "z", "a"));
		_listeUser.add(new User("user", "password", "M", "asd@asd.com", "User", "name"));
		_listeUser.add(new User("admin", "admin", "M", "asd@asd.com", "Admin", "Admin"));
		_listeUser.add(new User("z", "z", "M", "z@z.z", "Zed", "zed"));
		_listeUser.add(new User("a", "z", "M", "z@z.z", "z", "a"));
		_listeUser.add(new User("user", "password", "M", "asd@asd.com", "User", "name"));
		_listeUser.add(new User("admin", "admin", "M", "asd@asd.com", "Admin", "Admin"));
		_listeUser.add(new User("z", "z", "M", "z@z.z", "Zed", "zed"));
		_listeUser.add(new User("a", "z", "M", "z@z.z", "z", "a"));
		
		_listeEvent = new ArrayList<Event>();
		_listeEvent.add(new Event("Tamere", "est grosse", "19/10/10 10:30"));
		_listeEvent.add(new Event("Event1", "1", "19/10/10 10:30"));
		_listeEvent.add(new Event("adsadsadsf", "est grosse", "19/10/10 10:30"));
		_listeEvent.add(new Event("1341342", "est grosse", "19/10/10 10:30"));
		_listeEvent.add(new Event("qwerqwre", "est grosse", "19/10/10 10:30"));
		_listeEvent.add(new Event("bn,mbn,", "est grosse", "19/10/10 10:30"));
		_listeEvent.add(new Event("Tam7689789ere", "est grosse", "19/10/10 10:30"));
		_listeEvent.add(new Event("zxcvzxcv", "est grosse", "19/10/10 10:30"));
		_listeEvent.add(new Event("rtyurty", "est grosse", "19/10/10 10:30"));
		_listeEvent.add(new Event("Tamegfhjfghjre", "est grosse", "19/10/10 10:30"));
		_listeEvent.add(new Event("vbnmvbnm", "est grosse", "19/10/10 10:30"));
		_listeEvent.add(new Event("uiopuiop", "est grosse", "19/10/10 10:30"));
		_listeEvent.add(new Event("jkl;jkl", "est grosse", "19/10/10 10:30"));
		_listeEvent.add(new Event("hjklhjkl", "est grosse", "19/10/10 10:30"));
		_listeEvent.add(new Event("23452345", "est grosse", "19/10/10 10:30"));
		_listeEvent.add(new Event("97807890", "est grosse", "19/10/10 10:30"));
		_listeEvent.add(new Event("3456fdgs", "z", "15/10/10 10:30"));
		_listeEvent.add(new Event("sdfg245", "a", "14/10/10 10:30"));
		
	}
	
	public static UserHandler getInstance(){
		 if(instance == null) {
	         instance = new UserHandler();
	      }
	      return instance;
	}
	
	public User getUserLoggedIn(){
		return this.userLogged;
	}
	
	public ArrayList<User> getAllUser(){
		return this._listeUser;
	}
	
	public ArrayList<Event> getHorraire(){
		return this._listeEvent;
	}
	
	public boolean addUser(User user){
		return _listeUser.add(user);
	}

	public boolean login(User user) {
		for(int i=0; i< this._listeUser.size(); i++){
			User u = this._listeUser.get(i);
			if(u.getUsername().equals(user.getUsername()) && u.getPassword().equals(user.getPassword())){
				userLogged = u;
				return true;
			}
		}
		
		return false;		
	}

	public void disconnectUser() {
		userLogged = null;
	}
}
